#ifndef _TITLES_H_
#define _TITLES_H_


#include "Common.h"
#include "String.h"
#include "SharedPtr.h"
#include "Resource.h"
#include "Vector3.h"
#include "EffectModels.h"

class CreatureAIScript;

//头衔公共属性
typedef struct title_common_property
{
	ResourceProxy		uplink;
	void initialize(void)
	{
		uplink.setNull();
	}

	title_common_property()
	{
		initialize();
	}

}title_common_property_t;

class Title :public Resource
{
public:
	enum TitleStatus
	{
		TitleStatusNone			= 0,	//无效状态
		TitleStatusFree			= 1,	//头衔空闲
		TitleStatusUsed			= 2,	//头衔被占用
		TitleStatusError		= 4,	//头衔错误
		TitleStatusDeleted		= 255	//头衔删除删除
	};

	enum TitleFlag
	{
		TitleFlagNormal			= 0x01,		//一般头衔
		TitleFlagItem			= 0x02,		//物品头衔
	};

	Title(ResourceManager* creator, const String& name, ResourceHandle handle,
            const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
	~Title(void);

protected:
       	void prepareImpl(void);
        /** Destroys data cached by prepareImpl.
         */
        void unprepareImpl(void);
        /// @copydoc Resource::loadImpl
        bool loadImpl(void);
        /// @copydoc Resource::postLoadImpl
        void postLoadImpl(void);

	 void preUnloadImpl(void);
        /// @copydoc Resource::unloadImpl
        void unloadImpl(void);
        /// @copydoc Resource::calculateSize
        size_t calculateSize(void) const;

private:
	uint32		m_serial;
	uint32		m_group_id;

	void    initialize(void);
public:

	const uint32  & getSerial() 	{	return m_serial;	}
	const uint32  & getGroupID()	{	return m_group_id;	}

	//save item to database	
	bool	SaveDB(void);
	bool	LoadDB(void);
	bool    FetchDB(Field * fields);

	TitleStatus getTitleStatus(void);
	void	setTitleStatus(const TitleStatus & status);

	//公共属性
	title_common_property_t	common;
};

    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to TitlePtr 
    @note Has to be a subclass since we need operator=.
    We could templatise this instead of repeating per Resource subclass, 
    except to do so requires a form VC6 does not support i.e.
    ResourceSubclassPtr<T> : public SharedPtr<T>
    */
    class SERVER_DECL  TitlePtr : public SharedPtr<Title>
    {
    public:
        TitlePtr() : SharedPtr<Title>() {}
        explicit TitlePtr(Title* rep) : SharedPtr<Title>(rep) {}
        TitlePtr(const TitlePtr& r) : SharedPtr<Title>(r) {}
        TitlePtr(const ResourcePtr& r);
        /// Operator used to convert a ResourcePtr to a MeshPtr
        TitlePtr& operator=(const ResourcePtr& r);
    protected:
        /// Override destroy since we need to delete Mesh after fully defined
        void destroy(void);
    };
	

#endif
